<!-- 修改发货信息 -->
<template>
  <el-dialog
    title="修改收货信息"
    :visible.sync="dialogVisible3"
    width="30%"
    :before-close="closeChangeAddress"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form :model="form"  label-width="100px">
        <el-form-item label="收件人">
          <el-input v-model="form.name" placeholder="请输入收件人姓名"></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="form.phone" placeholder="请输入联系电话"></el-input>
        </el-form-item>
        <el-form-item label="收货地址">
          <el-input v-model="form.detailAddress" placeholder="请输入详细收货地址"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary"  @click="changedetail(form)">修改</el-button>
            <el-button @click="handleClose">取消</el-button>
        </el-form-item>
    </el-form>
  </el-dialog>
</template>
 
 <script>
 import { updateAddress ,updateToshippedAddress} from '@/api/api';
export default {
  name: "ChangeAddress",
  props: {
    orderID: {
      type: String,
      default: "",
    },
    dialogVisible2: {
      type: Boolean,
      default: false,
    },
    recivername: {
      type: String,
      default: "",
    },
    reciverphone: {
      type: String,
      default: "",
    },
    reciveraddress: {
      type: String,
      default: "",
    },
    addressID:{
      type:String,
      default:''
    }
  },
  computed: {
    showDialog: {
      get() {
        return this.dialogVisible3;
      },
      set(val) {
        this.$emit("update:dialogVisible2", val);
      },
    },
  },
  watch: {
    orderID: {
      handler(newVal) {
        this.form.id = newVal;
      },
    },
    addressID:{
      handler(newVal){
        this.changeAddress.addressId=newVal;
        this.form.id=newVal;
      }
    },
    recivername: {
      handler(newVal) {
        this.form.name = newVal;
      },
      deep: true,
    },

    reciverphone: {
      handler(newVal) {
        this.form.phone = newVal;
      },
      deep: true,
    },
    reciveraddress: {
      handler(newVal) {
        this.form.detailAddress = newVal;
      },
      deep: true,
    },
  },
  data() {
    return {
      dialogVisible3: this.dialogVisible2,
      form: {
        id: this.addressID,
        name: this.recivername,
        phone: this.reciverphone,
        detailAddress: this.reciveraddress,
      },
      changeAddress:{
        addressId:this.addressID,
        orderId:this.orderID
      }
    };
  },
  methods: {
    handleClose() {
      this.dialogVisible3 = false;
      this.$emit("update:dialogVisible2", false);
      this.$emit("update:recivername", this.form.name);
      this.$emit("update:reciverphone", this.form.phone);
      this.$emit("update:reciveraddress", this.form.detailAddress);
    },
    closeChangeAddress() {
        console.log("关闭修改发货信息");
      this.dialogVisible3 = false;
      this.$emit( "update:dialogVisible2", false);
    },
    //修改订单信息
    async  changedetail(data){
      console.log(data);

      //
      // const res = await updateAddress(data);
      // console.log(res);
      // if (res.data.code === 200) {
      //   const res2 = await updateToshippedAddress(this.changeAddress);
      //   if(res2.data.code===200){
      //     this.$message.success("修改地址成功");
      //     this.handleClose();
      //     this.$parent.handleClose();
      //     this.$parent.$parent.getToBeShippedOrders(1)
      //   }else{
      //       this.$message.error(res2.msg);
      //     }
      //   }else{
      //    this.$message.error(res.msg);
      //    this.handleClose();
      //   this.$parent.handleClose();
      //   this.$parent.$parent.getToBeShippedOrders(1)
      // }
    }
  },
  async created() {

  },
  mounted() {

  },
};
</script>
 
 <style>
</style>